package com.cn.wanxi.servlet;

import com.cn.wanxi.model.CompanyModel;
import com.cn.wanxi.model.NavModel;
import com.cn.wanxi.service.*;
import com.cn.wanxi.service.impl.NavThreeServiceImpl;

import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;

public class CommonThreeServlet {
    static void getCompanyAndNavData(HttpServletRequest req, ICompanyService companyService) {
//        ICompanyService companyService= new CompanyThreeServiceImpl();
//        String path = req.getServletContext().getRealPath("/");
//        String[] outs = path.split("out");
//        path=outs[0]+"/web/";
//        System.out.println(path);
//        E:\wanxi\step-3\canyin03-0809\out\artifacts\canyin03_0809_war_exploded\web
//        怎么通过path拿到需要的路径？
//        怎么通过字符串拿到一部分的值？

        CompanyModel companyModel = companyService.getCompanyModel(getPath(req));
        req.setAttribute("companyModel", companyModel);

        INavService navService = new NavThreeServiceImpl();

        NavModel[] navModels = navService.getNavModels(getPath(req));
        req.setAttribute("navModels", navModels);
    }

    public static void main(String[] args) {
        String path = "E:\\wanxi\\step-3\\canyin03-0809\\out\\artifacts\\canyin03_0809_war_exploded\\web";
//        String substring = path.substring(3,5);
        String[] aa = path.split("out");
//        for (int i = 0; i <aa.length ; i++) {
//            System.out.println(aa[i]);
//        }
        System.out.println(Arrays.toString(aa));
    }

    static String getPath(HttpServletRequest req) {
        String path = req.getServletContext().getRealPath("/");
        String[] outs = path.split("out");
        path = outs[0] + "/web/";
        return path;
    }
}
